<?php

declare(strict_types=1);

namespace Service\ChannelWechatService;

use App\Model\BbcModel\ConfigChannel;
use Service\BaseService;
use Service\Code\Normal;

class ChannelWechatService extends BaseService
{
    /**
     * 获取微信配置
     * @return array
     */
    public function getChannelWechatConfig(int $cid): array
    {
        $channelWechatConfigData = ConfigChannel::instance()->info(['cid'=>$cid,'code'=>'wxmp_pay']);
        if(empty($channelWechatConfigData) || empty($channelWechatConfigData['value'])){
            return Normal::returnCode(Normal::FAIL,'没有相关公众号参数');
        }
        $channelWechatConfig = json_decode($channelWechatConfigData,true);
        $config = [
            'appid' => $channelWechatConfig['appid'],
            'appsecret' => $channelWechatConfig['appsecret'],
            'mch_id' => $channelWechatConfig['mch_id'],
            'key' => $channelWechatConfig['key'],
            'cert' => $channelWechatConfig['cert'],
            'cid' => $channelWechatConfig['cid'],
        ];
        return Normal::returnCode(Normal::SUC,'获取成功',[
            'code' => 'wxmp_pay',
            'value' => $config
        ]);
    }
}
